package lw.shulkerdupe.events;


import lw.shulkerdupe.Main;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

import java.util.HashMap;

public class Dupe implements Listener {


    private HashMap<Player, Integer> count;

    @EventHandler
    public void onPlaceBlock(BlockPlaceEvent event) {
        Player player = event.getPlayer();
            this.count = new HashMap<>();
            this.count.putIfAbsent(player, Integer.valueOf(1));
            if (event.getBlock().getType().equals(Material.WHITE_SHULKER_BOX) || event
                    .getBlock().getType().equals(Material.ORANGE_SHULKER_BOX) || event
                    .getBlock().getType().equals(Material.PINK_SHULKER_BOX) || event
                    .getBlock().getType().equals(Material.LIGHT_BLUE_SHULKER_BOX) || event
                    .getBlock().getType().equals(Material.YELLOW_SHULKER_BOX) || event
                    .getBlock().getType().equals(Material.GREEN_SHULKER_BOX) || event
                    .getBlock().getType().equals(Material.BLACK_SHULKER_BOX) || event
                    .getBlock().getType().equals(Material.BLUE_SHULKER_BOX) || event
                    .getBlock().getType().equals(Material.BROWN_SHULKER_BOX) || event
                    .getBlock().getType().equals(Material.CYAN_SHULKER_BOX) || event
                    .getBlock().getType().equals(Material.GRAY_SHULKER_BOX) || event
                    .getBlock().getType().equals(Material.LIME_SHULKER_BOX) || event
                    .getBlock().getType().equals(Material.MAGENTA_SHULKER_BOX) || event
                    .getBlock().getType().equals(Material.PURPLE_SHULKER_BOX) || event
                    .getBlock().getType().equals(Material.RED_SHULKER_BOX)) {

                    this.count.put(player, Integer.valueOf(((Integer)this.count.get(player)).intValue() + 1));
                    if (((Integer)this.count.get(player)).intValue() == 11) {
                        ItemStack box = new ItemStack(event.getBlock().getType());
                        ItemMeta boxMeta = event.getItemInHand().getItemMeta();
                        box.setItemMeta(boxMeta);
                        player.getInventory().addItem(new ItemStack[] { box });
                        this.count.put(player, Integer.valueOf(1));
                    }
            }

    }
}
